#include "step.h"

Step::Step(unsigned int i): index(i)
{
    isAPass = false;
    coo.first = 0; coo.second = 0;

    for(register int ix=1; ix<DIMENSION-1; ix++)
    {
        for(register int iy=1; iy<DIMENSION-1; iy++)
        {
            board[ix][iy]=VOID;
            block[ix][iy]=0;
            ko[ix][iy]=0;
        }
    }
    for(int ix=0; ix<DIMENSION; ix++){
        board[ix][0]=GRID;
        board[ix][DIMENSION-1]=GRID;
        board[0][ix]=GRID;
        board[DIMENSION-1][ix]=GRID;
    }

    if(!(all_block.empty()))
    {
        all_block.erase(all_block.begin(), all_block.end());
    }

    if(!(deadStones.empty()))
    {
        deadStones.erase(deadStones.begin(), deadStones.end());
    }
}

/* *******************write Functions******************* */
/* *******************write Functions******************* */
/* *******************write Functions******************* */

void Step::writeColor(int c)
{
    color = c;
}

void Step::writeCoordinate(int x,int y)
{
    coo.first = x;
    coo.second = y;
}

void Step::writeDeadStones(int x ,int y)
{
    coordinate c;
    c.first = x;
    c.second = y;

    deadStones.push_back(c);
}

void Step::writeBoard(int (*pboard)[DIMENSION])
{
    for (register int i = 1; i<DIMENSION-1; i++)
    {
        for (register int j = 1; j<DIMENSION-1; j++)
        {
            board[i][j] = pboard[i][j];
        }
    }
}


void Step::writeKo(int (*pko)[DIMENSION])
{
    for (register int i = 1; i<DIMENSION-1; i++)
    {
        for (register int j = 1; j<DIMENSION-1; j++)
        {
            ko[i][j] = pko[i][j];
        }
    }
}

void Step::writeBlock(unsigned int (*pblock)[DIMENSION])
{
    for (register int i = 1; i<DIMENSION-1; i++)
    {
        for (register int j = 1; j<DIMENSION-1; j++)
        {
            block[i][j] = pblock[i][j];
        }
    }
}

void Step::writeAllBlock(map<int,series> *pallblock)
{
    all_block = *pallblock;
}

void Step::writePass()
{
    isAPass = true;
}



/* *******************get Functions******************* */
/* *******************get Functions******************* */
/* *******************get Functions******************* */

unsigned int Step::getIndex()
{
    return index;
}

int Step::getColor()
{
    return color;
}

int Step::getCoordinateX()
{
    if(!isAPass) return coo.first;
    else return 0;
}

int Step::getCoordinateY()
{
    if(!isAPass) return coo.second;
    else return 0;
}

/*void Step::getDeadStones(series *pdeadstones)
{
    if(!(pdeadstones->empty()))
    {
        pdeadstones->erase(pdeadstones->begin(), pdeadstones->end());
    }
    if(deadStones.empty())
    {
        pdeadstones = 0; //设为空指针
    }
    else
    {
        *pdeadstones = deadStones;
    }
}*/

unsigned int Step::getNumOfDeadStones()
{
    unsigned int num = 0;
    if(deadStones.empty())
    {
        num = 0;
    }
    else
    {
        vector<coordinate>::iterator iter;
        for(iter=deadStones.begin(); iter!=deadStones.end(); iter++)
        {
            num++;
        }
    }

    return num;
}

void Step::getBoard(int (*pboard)[DIMENSION])
{
    for (register int i = 1; i<DIMENSION-1; i++)
    {
        for (register int j = 1; j<DIMENSION-1; j++)
        {
            pboard[i][j] = board[i][j];
        }
    }
}

void Step::getKo(int (*pko)[DIMENSION])
{
    for (register int i = 1; i<DIMENSION-1; i++)
    {
        for (register int j = 1; j<DIMENSION-1; j++)
        {
            pko[i][j] = ko[i][j];
        }
    }
}

void Step::getBlock(unsigned int (*pblock)[DIMENSION])
{
    for (register int i = 1; i<DIMENSION-1; i++)
    {
        for (register int j = 1; j<DIMENSION-1; j++)
        {
            pblock[i][j] = block[i][j];
        }
    }
}

void Step::getAllBlock(map<int,series> *pallblock)
{
    if(!(pallblock->empty()))
    {
        pallblock->erase(pallblock->begin(), pallblock->end());
    }
    *pallblock = all_block;
}

bool Step::ifPass()
{
    return isAPass;
}
